<?php

/*
 * Banners
 */

class Banners extends Controller {
    public $lenguaje='spanish';

    function Banners()
    {
        parent::Controller();
        if(!$this->session->userdata('logged_in'))
        redirect('/home/');
        $this->lang->load('texto',$this->lenguaje);
    }

    function index()
    {
        $datos['titulo_pagina'] = 'Banners';
        $this->load->view('admin/encabezado_admin.php', $datos);
        $this->load->view('admin/menu_admin.php');
        $consulta['contenido'] = $this->db->query('SELECT * FROM banners');
        $this->load->view('admin/banners.php',$consulta);
        $this->load->view('admin/pie_admin.php');
    }

    function crear()
    {
        $datos['titulo_pagina'] = 'Banners';
        $this->load->view('admin/encabezado_admin.php', $datos);
        $this->load->view('admin/menu_admin.php');
        $this->load->library('fckeditor','num1');
        $this->fckeditor->BasePath = base_url().'system/plugins/fckeditor/';
        $this->fckeditor->ToolbarSet = 'Default';
        $this->fckeditor->Height = '500';
        $consulta['fck1'] = $this->fckeditor->CreateHtml();

        $this->fckeditor->InstanceName = 'num2';
        $consulta['fck2'] = $this->fckeditor->CreateHtml();

        $this->load->view('admin/am_banners.php',$consulta);
        $this->load->view('admin/pie_admin.php');
    }

    function editar()
    {
        $id = $this->uri->segment(4);
        $datos['titulo_pagina'] = 'Banners';
        $this->load->view('admin/encabezado_admin.php', $datos);
        $this->load->view('admin/menu_admin.php');
        $consulta['query'] = $this->db->query("SELECT * FROM banners WHERE id=".$id);
        $fila = $consulta['query']->row();
        
        $this->load->library('fckeditor','num1');
        $this->fckeditor->BasePath = base_url().'system/plugins/fckeditor/';
        $this->fckeditor->ToolbarSet = 'Default';
        $this->fckeditor->Height = '500';
        $this->fckeditor->Value=$fila->texto;
        $consulta['fck1'] = $this->fckeditor->CreateHtml();
    
        $this->fckeditor->InstanceName = 'num2';
        $this->fckeditor->Value=$fila->texto_ampliado;
        $consulta['fck2'] = $this->fckeditor->CreateHtml();

        $this->load->view('admin/am_banners.php',$consulta);
        $this->load->view('admin/pie_admin.php');
    }

    function guardar()
    {
        $id = $this->input->post('id');
        $texto = $this->input->post('num1');
        $texto_ampliado = $this->input->post('num2');
        $nombre = $this->input->post('nombre');
        $peso = $this->input->post('peso');
        $tipo = $this->input->post('tipo');

        if($this->db->simple_query("SELECT * FROM banners WHERE id=".$id)){
            $query = $this->db->query("UPDATE banners set nombre='".$nombre."', texto='".$texto."', texto_ampliado='".$texto_ampliado."', peso='".$peso."', tipo='".$tipo."' WHERE id=".$id);
        }else{
            $query = $this->db->query("INSERT INTO banners set nombre='".$nombre."', texto='".$texto."', texto_ampliado='".$texto_ampliado."', peso='".$peso."', tipo='".$tipo."'");
        }
        redirect('/admin/banners');
    }
    
    function eliminar()
    {
        $id = $this->uri->segment(4);
        $query = $this->db->query("DELETE from banners WHERE id=".$id);
        redirect('/admin/banners');
    }
   
}
?>